Return to doc.sitecore.com

Reading value of ASPNET controls in sublayout Page_Load event
Prev Next

Author: Alexander Tsvirchkov
Posted: 1/14/2008 12:53:44 PM

Problem: I use a sublayout on a layout via a placeholder. When I read the usual ASP.NET Textbox value in the Page_Load event I get an empty value. For example:

public partial class SubMain : System.Web.UI.UserControl

{

     protected void Page_Load(object sender, EventArgs e)

     {

         Response.Write(TextBox1.Text);  // The value is empty! But mustn’t

      }

      protected void Button1_Click(object sender, EventArgs e)

     {

         Response.Write(TextBox1.Text);  //The value in not empty  

      }

 }

Answer: This issue has been fixed in Sitecore CMS v5.3.2. Please have a look at this issue.

"For each placeholder nesting level, init event of controls at a ‘deeper’ level is fired after the load event of an ‘upper-level’ control."

You should either upgrade your solution to v5.3.2 or read the values via a request collection in the Page_Load event i.e.:

protected void Page_Load(object sender, EventArgs e)

{

         Response.Write(TextBox1.Text); // <- empty in 5.3.1

         Response.Write("Request:" + Request.Form[TextBox1.UniqueID]); // read the value in 5.3.1

}


Prev Next